package worker

import (
	"encoding/json"
	"os"
)

var G_config *Config

type Config struct {
	EtcdEndPoints         []string `json:"etcd_end_points"`
	EtcdDialTimeout       int      `json:"etcd_dial_timeout"`
	MongodbUri            string   `json:"mongodb_uri"`
	MongodbConnectTimeout int      `json:"mongodb_connect_timeout"`
	JobLogBatchSize       int      `json:"job_log_batch_size"`
	JobLogCommitTimeout   int      `json:"job_log_commit_timeout"`
}

// InitConfig 加载配置
func InitConfig(filePath string) (err error) {
	var config Config
	bytes, err := os.ReadFile(filePath)
	if err != nil {
		return
	}

	err = json.Unmarshal(bytes, &config)
	if err != nil {
		return
	}

	G_config = &config
	return
}
